<?php

require_once   BaseUtil::getModulePath("acl")  .  '/services/AAService.php';

class BaseController extends Zend_Controller_Action {

    protected $_redirector = null;

    protected $_translate = null;

    public function init() {
        $this->_redirector = $this->_helper->getHelper('Redirector');
        //locale init
        $controller = $this->getRequest()->getControllerName();
        $lan_cou = strtolower(Zend_Registry::get ( 'lan_cou'));
        $language = strtolower(Zend_Registry::get ( 'language'));
        $controllerLocaleDir = Zend_Registry::get("documentRoot") . "/data/$lan_cou/" . $controller .".ini";
        $commonLocaleDir = Zend_Registry::get("documentRoot") . "/data/$lan_cou/common.ini";
        $translate = new Zend_Translate('ini', $commonLocaleDir, $language);
        if(file_exists($controllerLocaleDir)) {
            $translate->addTranslation($controllerLocaleDir,$language);
        }
        $this->_translate = $translate;
        Zend_Registry::set('Zend_Translate', $translate);
        //action name
        $action = $this->getRequest()->getActionName();
        if(!AAService::isExcept($controller, $action)) {
            $allow = AAService::isAllowed($controller, $action);
            if(!$allow) {
                $this->_redirect('/acl/acl/noaccess');
            }
        }
        //set view escape
        $this->view->setEscape('stripslashes');
        //Global Config
        $config = Zend_Registry::get("config");
        $this->view->globalConfig = $config;
    }

    protected function addLocaleData($fileName) {
        $fileName = strtolower($fileName);
        //add other control ini
        $translate = Zend_Registry::get('Zend_Translate');
        $lan_cou = strtolower(Zend_Registry::get ( 'lan_cou'));
        $language = strtolower(Zend_Registry::get ( 'language'));
        $aclLocaleDir = Zend_Registry::get("documentRoot") . "/data/$lan_cou/$fileName.ini";
        $translate->addTranslation($aclLocaleDir,$language);
    }
    
}
